package com.booter.webflux.model;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.FieldType;
import org.springframework.data.mongodb.core.mapping.MongoId;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

@Data
@Document(collection = "t_menu")
public class Menu implements Serializable {

    private static final long serialVersionUID = 7554702640261532691L;

    @Id
    @MongoId(value = FieldType.STRING, targetType = FieldType.STRING)
    @Field(value = "_id", targetType = FieldType.STRING)
    private String id;
    /***
     *Automatic index creation will be disabled by default as of Spring Data MongoDB 3.x.
     * @Indexed(name = "idx_name")
     **/
    @Indexed(name = "idx_name")
    private String name;
    private String uri;
    private Date createTime;
    private Date updateTime;

    public Menu() {
        //this.id = UUID.randomUUID().toString();
    }

    public Menu(String id) {
        this.id = id;
    }

    public Menu(String name, String uri) {
        this.name = name;
        this.uri = uri;
        this.createTime = new Date();
    }

    public String getIndex() {
        return "idx_name";
    }


    public String getUUid(String prefix) {
        return prefix.concat("-").concat(UUID.randomUUID().toString());
    }

    @Override
    public String toString() {
        return "new instant";
    }

}
